package com.meilai.project.controller.web.business.offer;


import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.business.offer.OfferFlowDTO;
import com.meilai.project.service.business.offer.OfferFlowService;
import com.meilai.project.service.business.offer.OfferTmpService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 报价审核表 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-01-11
 */
@RestController
@RequestMapping("api/web/offerFlow")
public class OfferFlowController {

    @Autowired
    private OfferFlowService service;

    @Autowired
    private OfferTmpService offerTmpService;

    @PostMapping("/save")
    @ApiOperation("保存到草稿箱")
    public CommonResult save(@RequestBody OfferFlowDTO dto, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.save(dto, true, wfData_id));
    }

    @PostMapping("/saveTmp")
    @ApiOperation("保存并开启流程")
    public CommonResult saveTmp(@RequestBody OfferFlowDTO dto, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.saveAndStartFlow(dto, wfData_id));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public CommonResult page(@RequestParam(name = "page", defaultValue = "1") Integer page,
                             @RequestParam(name = "page_size", defaultValue = "10") Integer page_size,
                             @RequestParam(name = "is_check_page") Boolean is_check_page,
                             @RequestParam(name = "name", required = false) String name) {
        return new CommonResult().success(service.page(page, page_size, name, is_check_page));
    }

    @PostMapping("/check")
    @ApiOperation("审核方法")
    public CommonResult check(@RequestParam("id") Long id,
                              @RequestParam("is_return") Boolean is_return,
                              @RequestParam(value = "opinion", required = false) String opinion) {
        return new CommonResult().success(service.check(id, is_return,opinion));
    }

    @GetMapping("/getOne")
    @ApiOperation("获取审核记录详细信息")
    public CommonResult getOne(@RequestParam("offer_flow_id") Long offer_flow_id) {
        return new CommonResult().success(offerTmpService.getMediaVO(offer_flow_id));
    }

    @GetMapping("/getInfoById")
    @ApiOperation("获取审核记录详情")
    public CommonResult getInfoById(@RequestParam("id") Long id) {
        return new CommonResult().success(service.getInfoById(id));
    }

    @GetMapping("/getCount")
    @ApiOperation("获取待审批的数量")
    public CommonResult getCount() {
        return new CommonResult().success(service.getCount());
    }


    @PostMapping("/remove")
    @ApiOperation("删除记录")
    public CommonResult remove(@RequestParam(value = "flow_id") Long flow_id, @RequestParam(value = "wfData_id") Long wf_data_id) {
        return new CommonResult().success(service.remove(flow_id, wf_data_id));
    }

    @PostMapping("/actualDelete")
    @ApiOperation("彻底删除记录")
    public CommonResult actualDelete(@RequestParam(value = "flow_id") Long flow_id, @RequestParam(value = "wfData_id") Long wf_data_id) {
        return new CommonResult().success(service.actualDelete(flow_id, wf_data_id));
    }
}

